/**
 * Sample React Native App
 * https://github.com/facebook/react-native
 *
 * @format
 * @flow
 */

import RfidModule from './component/Rfid'
import React, { Component } from "react";
import {
  StyleSheet,
  Alert,
  Button,
  StatusBar,
  DeviceEventEmitter,
} from 'react-native';

import {
  Colors
} from 'react-native/Libraries/NewAppScreen';


class RfidDemo extends Component {
  constructor() {
    super();
    this.state = { data: [] };
    RfidModule.init(); // rfid设备初始化
  }

  componentWillMount(){
    // 监听RFID扫描
    DeviceEventEmitter.addListener('onRfidReveice', function(rfids) {  
      alert(rfids);  
    });
  }

  componentWillUnmount(){
    RfidModule.destory(); // 释放扫描模块
  }

  render() {
    return (
      <>
        <StatusBar barStyle="dark-content" />
        <Button onPress={() => {
          RfidModule.scan();
        }}
        title="开启扫描" />
      </>
    );
  }
};

const styles = StyleSheet.create({
  scrollView: {
    backgroundColor: Colors.lighter,
  },
  engine: {
    position: 'absolute',
    right: 0,
  },
  body: {
    backgroundColor: Colors.white,
  },
  sectionContainer: {
    marginTop: 32,
    paddingHorizontal: 24,
  },
  sectionTitle: {
    fontSize: 24,
    fontWeight: '600',
    color: Colors.black,
  },
  sectionDescription: {
    marginTop: 8,
    fontSize: 18,
    fontWeight: '400',
    color: Colors.dark,
  },
  highlight: {
    fontWeight: '700',
  },
  footer: {
    color: Colors.dark,
    fontSize: 12,
    fontWeight: '600',
    padding: 4,
    paddingRight: 12,
    textAlign: 'right',
  },
});

export default RfidDemo;
